<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/address.css">
</head>
<body>
    <div class="box">
        <div class="header">
            <span class="back">back</span>
            <span>收货地址</span>
            <span class="add">新增地址</span>
        </div>
        <ul class="list">
            
        </ul>
    </div>
</body>
</html>
<script src="js/get.js"></script>
<script src="js/request.js"></script>
<script>
    //生成数据列表；
    request('/user','GET',null,function(dat){
      let data=JSON.parse(dat)
        $('.list').innerHTML=data.map(item=>{
            return `<div class="case">
                    <div class="left">
                        <p>${item.address}</p>
                        <p>${item.card}</p>  
                        <p>${item.name}(${item.sex})${item.tel}</p>  
                    </div>
                    <div class="edit">编辑</div>
                </div>`
        }).join('')
        getEdit(el('.list .edit'))
    })//请求数据
    //点击新增：
        $('.add').onclick=function(){
            location.href="./add.html?page=add"  
        }
    
    //点击编辑 跳转到编辑页面
    function getEdit(list){
        list.forEach((item,index)=>{
            item.onclick=function(){
                location.href=`./add.html?id=${index}&&page=edit`
                
            }
        })
    }
</script>